package com.fdb.efp.esb.service.impl.sed.loan;

import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.fdb.basic.framework.core.constant.ESBConstant;
import com.fdb.basic.framework.core.exception.ESBException;
import com.fdb.basic.framework.core.util.TraceUtil;
import com.fdb.efp.esb.service.bo.req.sed.loan.ReqCus2PersonalLoanBean;
import com.fdb.efp.esb.service.bo.resp.sed.loan.RespCus2PersonalLoanBean;
import com.fdb.efp.esb.service.client.ESBClientFactory;
import com.fdb.efp.esb.service.client.impl.LhxESBBeanCreator;
import com.fdb.efp.esb.service.facade.sed.loan.CusWhetherHasLoanService;

/**
 * 检校个贷是否存在额度接口实现
  * TODO
  * @author wanglihua
  * @since 2019年5月15日 下午3:45:42
  * @version 1.0
 */
@Service("cusWhetherHasLoanService")
public class CusWhetherHasLoanServiceImpl implements CusWhetherHasLoanService{

	private final Logger logger = LoggerFactory.getLogger(CusWhetherHasLoanServiceImpl.class);
	
	@Override
	public RespCus2PersonalLoanBean cusWhetherHasLoan(ReqCus2PersonalLoanBean reqCus2PersonalLoanBean) throws ESBException {
		logger.info("======>税e贷规则信息查询接口【"+ TraceUtil.getTraceId() +"_30230008_01】开始<======");
		RespCus2PersonalLoanBean respCus2PersonalLoanBean = new RespCus2PersonalLoanBean();
		try {
			/** @qiuyf 2019/05/25 测试 */
			/*respCus2PersonalLoanBean = ESBClientFactory.buildClient().withBody(reqCus2PersonalLoanBean).withTradeNo(ESBConstant.TRADE_CODE_30230008)
					.withScene(ESBConstant.SCENE_NO_01).withESBBeanFactory(LhxESBBeanCreator.getINSTANCE()).create().sendAndReceive()
					.getBody(RespCus2PersonalLoanBean.class);*/
//			respCus2PersonalLoanBean.setClntNm(reqCus2PersonalLoanBean.getClntNm());
//			respCus2PersonalLoanBean.setCertNo(reqCus2PersonalLoanBean.getCertNo());
			respCus2PersonalLoanBean = ESBClientFactory.buildClient().withBody(reqCus2PersonalLoanBean).withTradeNo(ESBConstant.TRADE_CODE_30230008)
					.withScene(ESBConstant.SCENE_NO_01).withESBBeanFactory(LhxESBBeanCreator.getINSTANCE()).create().sendAndReceive()
					.getBody(RespCus2PersonalLoanBean.class);
			if(Objects.isNull(respCus2PersonalLoanBean)) {
				throw new ESBException("调用个贷是否存在额度接口，得到的结果为空！");
			}
		} catch (ESBException e) {
			logger.info("调用个贷是否存在额度接口失败！" + e.getMessage());
			throw e;
		} catch (Exception e) {
			logger.info("调用个贷是否存在额度接口失败！" + e.getMessage());
			throw e;
		} finally {
			logger.info("======>税e贷规则信息查询接口【"+ TraceUtil.getTraceId() +"_30230008_01】结束<======");
		}
		return respCus2PersonalLoanBean;
	}

}
